package com.jackiechan.hello.day02;

import java.util.Scanner;

/**
 * 测试正则表达式，并尝试编写规则: 电话号码可能有3-4位区号，
 * 7-8位号码:0415-5561111
 * @author Xiloer
 *
 */
public class Test06 {
    public static void main(String[] args) {
        regular();
    }

    private static void regular() {
        System.out.print("请输入电话号码:");
        String phoneNumber = new Scanner(System.in).nextLine();
        if (phoneNumber.matches("[0-9]{3,4}-[0-9]{7,8}")){
            System.out.println(phoneNumber);
            return;
        }
        if (!(phoneNumber.matches("^[0-9]{3,4}[-].*"))){
            System.out.println("区号错误");
        }
        if (!(phoneNumber.matches(".*[-][0-9]{7,8}$"))){
            System.out.println("电话号码错误");
        }
        regular();
    }
}
